home *** CD-ROM | disk | FTP | other *** search
- #import <Carbon/Carbon.h>
- #import <pthread.h>
-
- #define ABS(x) ( (x) < 0 ? -(x) : (x) )
-
- // Functions to patch
- extern OSStatus
- CreateNewwindoW(WindowClass class, WindowAttributes attributes, const Rect *rect,
- WindowRef *outWindow);
-
- extern void
- ShowwindoW(WindowRef window);
-
- extern OSStatus
- CreateNewWindow(WindowClass class, WindowAttributes attributes, const Rect *rect,
- WindowRef *outWindow)
- {
- OSStatus result;
-
- result = CreateNewwindoW(class, attributes, rect, outWindow);
-
- return result;
- }
-
-
-
- Boolean KeyDown(KeyMap gkm, int k)
- {
- return((((unsigned char *)gkm)[k>>3]>>(k&7))&1);
- }
-
- #define kSizeBuffer 10
- #define kShift 0x39
- #define kXOff .82
- #define kYOff .82
- #define kYAcc .1
- #define kXAcc .1
-
- extern void
- ShowWindow(WindowRef window)
- {
- KeyMap map;
-
- printf("ShowWindow called.\n");
-
- GetKeys(map);
- if(window && !KeyDown(map, kShift))
- {
- Rect endBounds;
- Rect bounds;
- float xOffset = kXOff, yOffset = kYOff;
- float xAcc = kXAcc, yAcc = kYAcc;
- float dx, dy;
- float x, y;
- float mult;
- float shortLength;
- Point center;
- Str255 title;
- short fullTitleLength, i;
- long count;
- Boolean growing;
-
- GetWTitle(window, title);
- fullTitleLength = title[0];
- title[0] = 0; // begin with the title undrawn - draw no characters
- SetWTitle(window, title);
-
- GetWindowBounds(window, kWindowContentRgn, &endBounds);
- center.h = (endBounds.right + endBounds.left) >> 1;
- center.v = (endBounds.bottom + endBounds.top) >> 1;
- dx = endBounds.right - center.h;
- dy = endBounds.bottom - center.v;
-
- if(dx == 0 || dy == 0) // We don't bother if the window is super-duper annorexic
- {
- ShowwindoW(window);
- return;
- }
-
- // Set the proportions of the beginning rectangle, velocity, and accellerations
- if(dx < dy) {
- mult = dy / dx;
- yAcc *= mult;
- yOffset *= mult;
- x = kSizeBuffer;
- y = kSizeBuffer * mult;
- shortLength = dx;
- } else {
- mult = dx / dy;
- xOffset *= mult;
- xAcc *= mult;
- x = kSizeBuffer * mult;
- y = kSizeBuffer;
- shortLength = dy;
- }
-
- // Set our actual window rects
- SetRect(&bounds, center.h - x, center.v - y, center.h + x, center.v + y);
-
- // If the window needs to shrink we set it to shrink
- if(x > dx) {
- xAcc = -xAcc;
- }
- if(y > dy) {
- yAcc = -yAcc;
- }
-
- // If our starting size matches the window size, we don't grow.
- if(dx == x) {
- xOffset = xAcc = 0;
- }
- if(dy == y) {
- yOffset = yAcc = 0;
- }
-
- // Set the new bounds of the window, and show
- SetWindowBounds(window, kWindowContentRgn, &bounds);
- ShowwindoW(window);
-
- growing = true; // begin growing
-
- // loop and grow
- while(growing)
- {
- // Handle the x-coordinate
- if(xOffset < 0) {
- x += xOffset;
- if(x <= dx)
- {
- xOffset = 0;
- x = dx;
- }
- } else if(xOffset > 0) {
- x += xOffset;
- if(x >= dx)
- {
- xOffset = 0;
- x = dx;
- }
- }
-
- // and the y-coord
- if(yOffset < 0) {
- y += yOffset;
- if(y <= dy)
- {
- yOffset = 0;
- y = dy;
- }
- } else if(yOffset > 0) {
- y += yOffset;
- if(y >= dy)
- {
- yOffset = 0;
- y = dy;
- }
- }
-
- if( xOffset == 0 && yOffset == 0) { // if the offsets have both been set to 0, we're done
- growing = false;
- } else {
- GetKeys(map);
- if(KeyDown(map, kShift) == true) // if they pressed shift, break the loop
- growing = false;
- else
- {
- // ... otherwise, we just set the bounds of the window.
- bounds.left = (int)(center.h - x);
- bounds.right = (int)(center.h + x);
- bounds.top = (int)(center.v - y);
- bounds.bottom = (int)(center.v + y);
- SetWindowBounds(window, kWindowContentRgn, &bounds);
- xOffset += xAcc;
- yOffset += yAcc;
- }
- }
- }
- SetWindowBounds(window, kWindowContentRgn, &endBounds);
-
- #define kTitleWait 5
- for(i = 1; i <= fullTitleLength; i++)
- {
- count = TickCount() + kTitleWait;
- title[0] = i;
- SetWTitle(window, title);
- while(count > TickCount())
- ; // animation waiting
- }
- }
-
- else // Otherwise, we don't care so we tell the system to do its thing
- ShowwindoW(window);
- }